package com.karrim.server.util.array;

import com.karrim.server.util.array.def.DynamicArray;
import java.util.Arrays;

/**
 *
 * @author andrea.cantafio
 */
public class ArrayUtils {
    public static <T> T[] addAll(T[] dest, T[] source) {
        System.arraycopy(source, 0, dest, 0, dest.length);
        return dest;
    }
    
    public static <T> T[] addAll(T[] dest, T[] ... sources) {
        int size = dest.length;
        for (T[] t : sources) {
            size += t.length;
        }
        T[] result = Arrays.copyOf(dest, size);
        int offset = dest.length;
        for (T[] t : sources) {
            int length = t.length;
            System.arraycopy(t, 0, result, offset, length);
            offset += length;
        }
        return result;
    }
    
    public static <T> boolean isDynamic (T t) {
        return (t instanceof DynamicArray);
    }
}
